﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Components_ContentBloc : System.Web.UI.UserControl
{
    public string ItemTitle { get; set; }
    public string SectionName { get; set; }
    public bool ShowTitle { get; set; }     
    protected void Page_Load(object sender, EventArgs e)
    {
        string mapLoc = HttpContext.Current.Request.MapPath("~/Content/" + SectionName + ".xml");
        XElement m = XElement.Load(mapLoc);
        XElement item = (from el in m.Elements("item")
                         where (string)el.Element("title") == ItemTitle
                         select el).First();
        if (ShowTitle)
        {
            Title.Text = item.Element("title").Value;
            if (item.Element("subtitle").ToString().Length < 1)
                SubTitle.Visible = false;
            else
                SubTitle.Text = item.Element("subtitle").ToString();
        }
        HtmlGenericControl cnt = new HtmlGenericControl("div");
        cnt.InnerHtml = item.Element("content").ToString();
        Content.Controls.Add(cnt);
    }
}